package cn.stylefeng.guns.modular.ums.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ums.entity.MemberAccountRecords;
import cn.stylefeng.guns.modular.ums.mapper.MemberAccountRecordsMapper;
import cn.stylefeng.guns.modular.ums.model.params.MemberAccountRecordsParam;
import cn.stylefeng.guns.modular.ums.model.result.MemberAccountRecordsResult;
import  cn.stylefeng.guns.modular.ums.service.MemberAccountRecordsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 会员账户流水表 服务实现类
 * </p>
 *
 * @author yzb
 * @since 2022-05-07
 */
@Service
public class MemberAccountRecordsServiceImpl extends ServiceImpl<MemberAccountRecordsMapper, MemberAccountRecords> implements MemberAccountRecordsService {

    @Override
    public MemberAccountRecordsResult getStatistics(MemberAccountRecordsParam paramCondition) {
        return this.baseMapper.getStatistics(paramCondition);
    }

    @Override
    public void add(MemberAccountRecordsParam param){
        MemberAccountRecords entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MemberAccountRecordsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MemberAccountRecordsParam param){
        MemberAccountRecords oldEntity = getOldEntity(param);
        MemberAccountRecords newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MemberAccountRecordsResult findBySpec(MemberAccountRecordsParam param){
        return null;
    }

    @Override
    public List<MemberAccountRecordsResult> findListBySpec(MemberAccountRecordsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(MemberAccountRecordsParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpecForAdmin(MemberAccountRecordsParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListForAdmin(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(MemberAccountRecordsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MemberAccountRecords getOldEntity(MemberAccountRecordsParam param) {
        return this.getById(getKey(param));
    }

    private MemberAccountRecords getEntity(MemberAccountRecordsParam param) {
        MemberAccountRecords entity = new MemberAccountRecords();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
